package com.trafficsys.modules.loginAndRegister.dao;

import com.baomidou.mybatisplus.core.mapper.BaseMapper;
import com.baomidou.mybatisplus.core.metadata.IPage;
import com.trafficsys.modules.entity.DriveCard;
import com.trafficsys.modules.entity.Driver;
import com.trafficsys.modules.entity.Ticket;
import com.trafficsys.modules.entity.TravelCard;
import com.trafficsys.modules.licenseplaterecognition.vo.TicketVo;
import com.trafficsys.modules.loginAndRegister.pojo.TicketAndRule;
import org.apache.ibatis.annotations.Mapper;
import org.apache.ibatis.annotations.Param;
import org.apache.ibatis.annotations.Select;
import org.springframework.stereotype.Repository;

import java.util.List;

/**
 * @Author Zhao Bin
 * @Date 2021/9/27 9:01
 * @Version 1.0
 */
@Mapper
@Repository
public interface DriverDao extends BaseMapper<Driver> {
    //driver电话号码登录
    @Select("select * from driver where phone = #{phone} and password = #{password}")
    Driver loginByPhone(@Param("phone")String phone,@Param("password")String password);
    //driver身份证号码登录
    @Select("select * from driver where card_id = #{cardId} and password = #{password}")
    Driver loginByCardId(@Param("cardId")String cardId,@Param("password")String password);
    //driver根据phone查询用户
    @Select("select * from driver where phone = #{phone}")
    Driver getDriverByPhone(@Param("phone")String phone);
    @Select("select * from driver where card_id = #{cardId}")
    Driver getDriverByCardId(@Param("cardId")String cardId);
    //分页查询查询违章信息
    @Select("select * from ticket where car_no in (${carNo})")
    IPage<Ticket> getTicketsByCardId(IPage<Ticket> page, @Param("carNo") String carNo);
    //查询违章信息
    @Select("select * from ticket where car_no in (${carNo})")
    List<Ticket> getTicketListByCardId(@Param("carNo") String carNo);
    //查询已处理罚单及相应rule信息
    @Select("select t.id,t.car_no,t.police_id,t.create_time,t.update_time,t.state,r.id as rule_id,r.rule_name,r.money,r.cut_score from ticket t  inner join rule r\n" +
            "on r.id = t.rule_id\n" +
            "where car_no in (select tc.car_no from travel_card tc where card_id = #{cardId} ) and t.state= '已处理' ")
    IPage<TicketAndRule> getSolvedTicketAndRuleByCardId(IPage<TicketAndRule> page,@Param("cardId") String cardId);
    //查询未处理罚单及相应rule信息
    @Select("select t.id,t.car_no,t.police_id,t.create_time,t.update_time,t.state,r.id as rule_id,r.rule_name,r.money,r.cut_score from ticket t  inner join rule r\n" +
            "on r.id = t.rule_id\n" +
            "where car_no in (select tc.car_no from travel_card tc where card_id = #{cardId} ) and t.state= '未处理' ")
    IPage<TicketAndRule> getNoSolveTicketAndRuleByCardId(IPage<TicketAndRule> page,@Param("cardId") String cardId);

    @Select("SELECT t.* ,r.rule_name,r.cut_score,r.money FROM `ticket` t inner join rule r on t.rule_id = r.id")
    List<TicketAndRule> getAllTicketAndRule();
    //分页查询驾驶证信息
    @Select("select * from drive_card")
    IPage<DriveCard> getAllDriveCard(IPage<DriveCard> page);
    //分页查询行驶证信息
    @Select("select * from travel_card")
    IPage<TravelCard> getAllTravelCard(IPage<TravelCard> page);
}
